package com.dsbj.apolo.facecollector.service;


import com.uniubi.uface.JudgeResult;
import com.uniubi.uface.QualityJudge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sun.misc.BASE64Decoder;

import javax.jws.WebService;

@Service
@WebService(endpointInterface = "com.dsbj.apolo.facecollector.service.FaceWebService")
public class FaceWebServiceImpl implements FaceWebService {


    @Override
    public int judgeFaceImg(String photoBase64Data) {
        byte [] byteArray = base64ToBytes(photoBase64Data);
        QualityJudge judge = new QualityJudge(48);
        JudgeResult judgeResult = judge.judgeImage(byteArray);
        judge.release();
        return judgeResult.code;
    }

    private byte[] base64ToBytes(String imgStr){
        BASE64Decoder decoder = new BASE64Decoder();
        try
        {
            //Base64解码
            byte[] byteArray = decoder.decodeBuffer(imgStr);
            for(int i=0;i<byteArray.length;++i)
            {
                if(byteArray[i]<0)
                {//调整异常数据
                    byteArray[i]+=256;
                }
            }
            return byteArray;
        }
        catch (Exception e)
        {
            return null;
        }
    }

}
